import md5 from 'js-md5';
/**
 * @description 列表转树
 * @param {Array} list 列表
 * @param {Object} config 默认配置
 */
const DEFAULT_CONFIG = {
    id: "id",
    children: "children",
    pid: "parentId",
    title: "name",
    label: "name",
    value: "value",
    rootKey:''
  };
  export function listToTree(list, config = DEFAULT_CONFIG) {
    const treeConfig = Object.assign({}, DEFAULT_CONFIG, config);
    const nodeMap = new Map();
    const result = [];
    const { id, children, pid, title, label, value, rootKey } = treeConfig;
    for (const node of list) {
      node.title = node[title];
      node.label = node[label];
      node.value = node[value];
      node[children] = node[children] || [];
      nodeMap.set(node[id], node);
    }
    for (const node of list) {
      const parent = nodeMap.get(node[pid]);
      (parent ? parent[children] : result).push(node);
    }
    return result.filter(item => item[pid] === rootKey);
  }

  /**
 * md5加密
 * @param {string} str
 * @returns {string}
 */
export function encryptMd5 (str) {
    return md5 (str);
  }